{extend name="index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">优惠券列表管理</div>
    <div class="layui-card-body">
        <div class="layui-form">
            <table class="layui-hide" id="currentTable" lay-filter="currentTable"
                   data-auth-add="{:$auth->check('coupons.coupons/add')}"
                   data-auth-edit="{:$auth->check('coupons.coupons/edit')}"
                   data-auth-delete="{:$auth->check('coupons.coupons/del')}"></table>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/html" id="picTpl">
    <img style="max-width:100px; max-height:60px;" src="{{d.img_url}}" data-image="{{d.name}}">
</script>

<script type="text/html" id="barTool">

    <a class="layui-btn layui-btn-xs" data-open='{:url("edit")}?id={{ d.id }}' data-title="编辑内容"
       data-full="true">编辑

        <a class="layui-btn layui-btn-xs  layui-btn-normal" data-open='{:url("sendCoupons")}?id={{ d.id }}' data-title="发送优惠券">发送优惠券</a>
    {{# if(d.cate_id!=1){ }}
    <a href='{:url("del",["catid"=>$catid])}?ids={{ d.id }}'
       class="layui-btn layui-btn-danger layui-btn-xs layui-tr-del">删除</a>
    {{# } }}

</script>

<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" data-href='{:url("setstate")}?id={{d.id}}' value="{{d.id}}"
           lay-skin="switch"
           lay-text="启动|关闭" lay-filter="switchStatus" {{ d.status==1 ? 'checked' : '' }}>
</script>

<script type="text/javascript">
    layui.use('yznTable', function () {
        var table = layui.yznTable;

        var init = {
            table_elem: '#currentTable',
            table_render_id: 'currentTable',
            add_url: '{:url("add")}',
            edit_url: '{:url("edit")}',
            delete_url: '{:url("del")}',
        };
        var coupons_cate_list1 = {:json_encode($coupons_cate_list1)};

        table.render({
            init: init,
            toolbar: ['refresh', 'add'],
            url: '{:url("index")}',
            cols: [
                [
                    //优惠券名称
                    //所属分类
                    //面值
                    //最低消费
                    //可领取时间
                    //有效类型 天数 时间范围

                    //优惠券张数
                    //已领取张数
                    //创建时间

                    {field: 'id',fixed: 'left',   width: '4%', align: "center", title: 'ID'},
                    {field: 'name', width: '10%', align: "center", title: '名称', searchOp: 'like'},
                    {field: 'cate_name',width: '10%', align: "center", title: '所属分类', selectList: coupons_cate_list1},
                    {field: 'value', width: '8%', align: "center", title: '面值', search: 'false'},
                    {field: 'min_amount', width: '8%', align: "center", title: '最低消费', search: 'false'},
                    // {field: 'give_time', width: '35%', align: "center", title: '可领取时间', search: 'false'},
                    {
                        field: 'effect_type', width: '8%', align: "center", title: '有效类型', templet: function (d) {
                            if (d.effect_type == 1) {
                                return '<span style="color: #00B7EE">时间范围</span>';
                            } else if (d.effect_type == 2) {
                                return '<span style="color: #1d1e22 ">相对时间</span>';
                            }
                        }, search: 'false'
                    },
                    {field: 'total_count', width: '8%', align: "center", title: '优惠券张数', search: 'false'},
                    {field: 'claimed_count',width: '8%', align: "center", title: '已领取张数', search: 'false'},
                    {
                        field: 'status',
                        width: '10%',
                        align: "center",
                        title: '状态',
                        templet: '#statusTpl',
                        unresize: true,
                        selectList: {1: '启用', 2: '关闭'}
                    },
                    {field: 'create_time', width: '15%', align: "center", title: '创建时间', search: 'false'},
                    {fixed: 'right', width: '15%', align: "center", title: '操作', toolbar: '#barTool'}
                ]
            ],
            page: {}
        });

        yznTable.bindevent();
        selectElement2 = document.getElementById('searchFieldset_currentTable');
        selectElement2.classList.remove("layui-hide");
        var element = document.getElementById('layui-input-search');
        element.parentNode.removeChild(element);
    });
</script>
{/block}